package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.pojo.dto.AlbumUpdateDTO;
import cn.tedu.csmall.product.pojo.dto.CategoryDTO;
import cn.tedu.csmall.product.pojo.dto.CategoryUpdateDTO;
import cn.tedu.csmall.product.pojo.vo.AlbumStandardVO;
import cn.tedu.csmall.product.pojo.vo.CategoryListVO;
import cn.tedu.csmall.product.pojo.vo.CategoryStandardVO;
import cn.tedu.csmall.product.service.ICategoryService;
import cn.tedu.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.jar.JarEntry;


/**
 * ClassName: CategoryController
 * Package: cn.tedu.csmall.product.controller
 * Description 处理类别相关请求的控制器
 *
 * @version 0.0.1
 * @Author: 大傻
 * @Create:2022/11/30
 */
@Api(tags = "01.类别管理模块")
@RestController
@RequestMapping("/categories")
@Slf4j
public class CategoryController {
  @Autowired
    ICategoryService iCategoryService;
//    @Resource(name = "categoryService")
//    ICategoryService categoryService;
// http://localhost:9080/categories/add-new
    @ApiOperation("添加类别")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult addNew(@Validated CategoryDTO categoryDTO){
        iCategoryService.addNew(categoryDTO);
        return JsonResult.ok();
    }
    // http://localhost:8080/categories/1998/delete
    @ApiOperation("删除类别")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "类别ID", required = true, dataType = "long"),
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "long")
    })
    @PostMapping("/{id:[0-9]+}/delete")
    public void delete(Long userId, @PathVariable Long id) {

    }

    //http://localhost:9080/categories/1998/update
    @ApiOperation("修改类别")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParam(name = "id", value = "类别ID", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/update")
    public JsonResult updateInfoById(@PathVariable Long id, CategoryUpdateDTO categoryUpdateDTO){
        log.debug("开始处理修改相册基本信息的请求,参数id:{},新数据{}",id,categoryUpdateDTO);
        iCategoryService.updateInfoById(id, categoryUpdateDTO);
        return JsonResult.ok();
    }
    // http://localhost:9080/categories/1998/enable
    @ApiOperation("启用类别")
    @ApiOperationSupport(order = 310)
    @ApiImplicitParam(name = "id", value = "类别ID", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/enable")
    public JsonResult setEnable(@PathVariable Long id){
        log.debug("开始处理启用类别的业务，参数：{}", id);
        iCategoryService.setEnable(id);
        return JsonResult.ok();
    }
    // http://localhost:9080/categories/1998/disable
    @ApiOperation("禁用类别")
    @ApiOperationSupport(order = 311)
    @ApiImplicitParam(name ="id",value = "类别id",required = true,dataType = "long")
    @PostMapping("/{id:[0-9]+}/disable")
    public JsonResult setDisable(@PathVariable Long id){
        log.debug("开始处理 禁用类别的业务,参数:{}",id);
        iCategoryService.setDisable(id);
        return JsonResult.ok();
    }

    // http://localhost:9080/categories/1998/enableAppBar
    @ApiOperation("显示导航栏")
    @ApiOperationSupport(order = 312)
    @ApiImplicitParam(name ="id",value = "类别id",required = true,dataType = "long")
    @PostMapping("/{id:[0-9]+}/enableAppBar")
    public JsonResult setEnableDisplay(@PathVariable Long id){
        log.debug("开始处理 显示类别导航栏的业务,参数:{}",id);
        iCategoryService.setEnableDisplay(id);
        return JsonResult.ok();
    }
    // http://localhost:9080/categories/1998/disableAppBar
    @ApiOperation("隐藏导航栏")
    @ApiOperationSupport(order = 313)
    @ApiImplicitParam(name ="id",value = "类别id",required = true,dataType = "long")
    @PostMapping("/{id:[0-9]+}/disableAppBar")
    public JsonResult setDisableDisplay(@PathVariable Long id){
        log.debug("开始处理 隐藏导航栏的业务,参数:{}",id);
        iCategoryService.setDisableDisplay(id);
        return JsonResult.ok();
    }

    // http://localhost:8080/categories/1998
    @ApiOperation("根据id查询类别详情")
    @ApiOperationSupport(order = 410)
    @GetMapping("/{id:[0-9]+}")
    public JsonResult getStandardById(@PathVariable Long id) {
        log.debug("开始处理根据id查询类别详情的请求,参数:{}",id);
        CategoryStandardVO standardById = iCategoryService.getStandardById(id);

        return JsonResult.ok(standardById);
    }

    // http://localhost:8080/categories
    @ApiOperation("查询类别列表")
    @ApiOperationSupport(order = 420)
    @GetMapping("")
    public JsonResult list() {
        List<CategoryListVO> list = iCategoryService.list();
        return JsonResult.ok(list);

    }
  

}
